package com.yuanhua.rabbitmq.workqueue;

import com.rabbitmq.client.*;
import com.yuanhua.rabbitmq.utils.RabbitConstant;
import com.yuanhua.rabbitmq.utils.RabbitUtils;

import java.io.IOException;

public class SMSSender2 {

    public static void main(String[] args) throws IOException {
        Connection connection = RabbitUtils.getConnection();
        final Channel channel = connection.createChannel();
        //指定队列信息
        channel.queueDeclare(RabbitConstant.QUEUE_SMS, false, false,false,null);

        //处理完i个后再取下一个
        channel.basicQos(1);
        channel.basicConsume(RabbitConstant.QUEUE_SMS, false, new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {

                String msg = new  String(body);

                System.out.println("短信发送成功");
                channel.basicAck(envelope.getDeliveryTag(), false);
            }
        });
    }
}
